﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TimKen.DataEntity;
using TimKen.BussLogic;
using System.Data;

namespace TimKen.Web.Admin.IndustrySolution
{
    public partial class IndustrySolution_List : TimKen.App.AdminPage
    {
        public override string ActionCode
        {
            get
            {
                return "32";//成功案例列表
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindResources();
                BindData();
            }
        }

        public void BindResources()
        {
            btnSearch.Text = GetLangString("Search");
            ddlLanguage.Items.Clear();
            ddlLanguage.Items.Add(new ListItem("", "0"));
            ddlLanguage.Items.Add(new ListItem("简体中文", "1"));
            ddlLanguage.Items.Add(new ListItem("English", "2"));
        }

        protected void BindData()
        {
            ArticleManager am = new ArticleManager();
            string where = "   TypeID=3";

            if (ddlLanguage.SelectedValue != "0")
                where += " AND LanguageID=" + ddlLanguage.SelectedValue;

            if (!string.IsNullOrEmpty(this.txtKeyWord.Text.Trim()))
                where += " AND (Title LIKE '%" + this.txtKeyWord.Text.Trim() + "%' OR [Content] LIKE '%" + this.txtKeyWord.Text.Trim() + "%') ";

            if (!string.IsNullOrEmpty(this.txtCreateDateBegin.Text.Trim()))
                where += " AND  CreateDate >='" + Convert.ToDateTime(this.txtCreateDateBegin.Text.Trim()).ToString() + "'";

            if (!string.IsNullOrEmpty(this.txtCreateDateEnd.Text.Trim()))
                where += " AND  CreateDate <='" + Convert.ToDateTime(this.txtCreateDateEnd.Text.Trim()).ToString() + "'";

            DataSet ds = am.GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, where);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["total"]);

            this.grdArticleList.DataSource = ds.Tables[0].DefaultView;
            this.grdArticleList.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 0;
            BindData();
        }

        protected void grdArticleList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteEvent")
            {
                ArticleManager am = new ArticleManager();
                if (!string.IsNullOrEmpty(e.CommandArgument.ToString()))
                {
                    am.Delete(int.Parse(e.CommandArgument.ToString()));
                    BindData();
                }

            }
        }
    }
}
